package com.ruoyi.produce.base.circulatingWater.service;

import com.ruoyi.produce.base.circulatingWater.domain.CirculatingWater;
import com.ruoyi.produce.base.circulatingWater.domain.CirculatingWaterCond;
import com.ruoyi.produce.base.circulatingWater.domain.CirculatingWaterDto;
import com.ruoyi.produce.base.circulatingWater.mapper.CirculatingWaterMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class CirculatingWaterServiceImpl implements ICirculatingWaterService{
    @Autowired
    private CirculatingWaterMapper circulatingWaterMapper;

    @Override
    public List<CirculatingWaterDto> selectCirculatingWaterList(CirculatingWaterCond cond) {
        List<CirculatingWaterDto> resList = new ArrayList<>();
        List<CirculatingWater> circulatingWaterList = circulatingWaterMapper.selectCirculatingWaterList(cond);
        for (CirculatingWater item : circulatingWaterList) {
            // 除以10以及转换精度操作
            CirculatingWaterDto cw = new CirculatingWaterDto();
            cw.setWaterId(item.getWaterId());
            cw.setChillerTemperature1((float) item.getChillerTemperature1() / 10);
            cw.setChillerAlarm1(item.getChillerAlarm1());

            cw.setChillerStatus1(item.isChillerStatus1());
            cw.setChillerStatus2(item.getChillerStatus2());
            cw.setChillerAlarm2(item.getChillerAlarm2());
            cw.setChillerTemperature2((float) item.getChillerTemperature2() / 10);
            cw.setChillerTemperature3((float) item.getChillerTemperature3() / 10);
            cw.setChillerPressure1((float) item.getChillerPressure1() / 10);
            cw.setChillerPressure2((float) item.getChillerPressure2() / 10);

            cw.setChillerStatus3(item.isChillerStatus3());
            cw.setChillerStatus4(item.getChillerStatus4());
            cw.setChillerAlarm3(item.getChillerAlarm3());
            cw.setChillerTemperature4((float) item.getChillerTemperature4() / 10);
            cw.setChillerTemperature5((float) item.getChillerTemperature5() / 10);
            cw.setChillerPressure3((float) item.getChillerPressure3() / 10);
            cw.setChillerPressure4((float) item.getChillerPressure4() / 10);
            resList.add(cw);
        }
        return resList;
    }

    @Override
    public CirculatingWater selectCirculatingWaterById(String waterId) {
        return circulatingWaterMapper.selectCirculatingWaterById(waterId);
    }

    @Override
    public int insertCirculatingWater(CirculatingWater circulatingWater) {
        return circulatingWaterMapper.insertCirculatingWater(circulatingWater);
    }

    @Override
    public int updateCirculatingWater(CirculatingWater circulatingWater) {
        return circulatingWaterMapper.updateCirculatingWater(circulatingWater);
    }
}
